select * from ger_plano_de_contas_vi
select * from trb_tipo_tributo

select * from ger_plano_de_contas_vi where pla_cod_arrecadacao is not null


select pla_sigla, b.* from ger_plano_de_contas_vi a
join trb_tipo_tributo b on b.pla_cod = a.pla_cod
where pla_cod_arrecadacao is not null

9993338


Select * from TRB_empresa where pes_cod_empresa = 999999

Select * from TRB_iss where pes_cod_empresa = 999999

Select * from TRB_tipo_lancamento where tla_cod =  3494881

-- update trb_tipo_tributo set tri_digito_parcela = 6 where tri_cod = 5
4000100022000A
01234567890
SELECT top 100
	substring( imv_inscricao, 1, 10)
	, * 
FROM TRB_IMOVEL where imv_cod != imv_cadastro



select * from TRB_IMOVEL where imv_inscricao like '40314003670001%'

select case when isnumeric(imv_inscricao) then right( imv_inscricao, 4) else 0 end from TRB_IMOVEL where imv_inscricao like '4164300100%'

select * from TRB_IMOVEL_MASSA
update TRB_IMOVEL_MASSA set imv_cod = 79229



SELECT 
	substring( imv_inscricao, 1, 10)
	, * 
FROM TRB_IMOVEL where imv_cod != imv_cadastro

Select
  coalesce(Max(TRB_IMOVEL.imv_cadastro), 0) + 1
From
  TRB_IMOVEL

select * from TRB_IMOVEL_TESTADA

Select
  coalesce(Max(TRB_IMOVEL.imv_cadastro), 0) + 1
From
	TRB_IMOVEL_BCI









select imv_inscricao
	, isnumeric(imv_inscricao)
	, case when isnumeric( DBO.TRB_REPLACECHARS_FN(imv_inscricao) ) = 1 then right( imv_inscricao, 4) else '0' end
	, convert( int, case when isnumeric( DBO.TRB_REPLACECHARS_FN(imv_inscricao) ) = 1 then right( imv_inscricao, 4) else 0 end )
from TRB_IMOVEL 
where 
	-- imv_inscricao like '4164300100%'
	imv_inscricao like '%00D1'

select DBO.TRB_REPLACECHARS_FN('409090225400D1'),
	  isnumeric(DBO.TRB_REPLACECHARS_FN('409090225400D1'))
	, isnumeric('409090225400b1')
	, isnumeric('409090225400c1')	
	, isnumeric('409090225400D1')
	, isnumeric('409090225400E1')
	, isnumeric('409090225400F1')
	, isnumeric('409090225400G1') 




select MAX( convert( int, case when isnumeric( DBO.TRB_REPLACECHARS_FN(imv_inscricao) ) = 1 then right( imv_inscricao, 4) else 0 end ) )
from TRB_IMOVEL 
where 
	imv_inscricao like '4164300100%'
	


select 
MAX( convert( int, case when isnumeric( DBO.TRB_REPLACECHARS_FN(imv_inscricao) ) = 1 then right( imv_inscricao, 4) else -1 end ) )
from TRB_IMOVEL 
where 
	imv_inscricao like '4164300100%'
	
-- 41643001000000


select * from trb_situacao_imovel
select * from trb_edificio

select 
	edf_cod, *
from TRB_IMOVEL 
where 
	imv_inscricao like '4164300100%'


SQL("SELECT SES_USUARIO FROM FR_SESSAO_VI")
SQL("SELECT GETDATE()")

select * from sysobjects where xtype = 'U' and name like 'trb%divida%'

declare @d int, @v money
select @d = div_cod, @v = lan_valor_original from TRB_DIVIDA_LANCAMENTO a join trb_lancamento b on b.lan_cod = a.lan_cod where tla_cod = 856994 and b.lan_parcela = 0
select @d, @v
